package com.luffy.billservice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class BillController {

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

    @Autowired
    private RestTemplate restTemplate;

    @Bean("normalRestTemplate")
    public RestTemplate normalRestTemplate() {
        return new RestTemplate();
    }

    @Autowired
    @Qualifier("normalRestTemplate")
    RestTemplate normalRestTemplate;


    @GetMapping("/service/user")
    public String getUserInfo(){
        return restTemplate.getForObject("http://user-service/user", String.class);
    }

    @GetMapping("/normal")
    public String normal() {
        return normalRestTemplate.getForObject("http://localhost:7000/user", String.class);
    }
}